﻿using System.Collections;
using FX.CC.Andon.Entity.BasicDataManage;
using FX.CC.Andon.Service.BasicDataManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.BasicDataManage
{
    /// <summary>
    /// 异常类别业务层
    /// </summary>
    public class ETypeBusiness
    {
        private readonly ETypeService _dal = new ETypeService();

        /// <summary>
        /// 获取异常类别绑定下拉列表
        /// </summary>
        /// <returns></returns>
        public string GetETypeList()
        {
            return JsonHelper.Encode(_dal.GetETypeList());
        }

        /// <summary>
        /// 添加异常类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddEType(string data)
        {
            var model = new ETypeEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.ETypeCode = row["ETypeCode"].ToString();
                model.ETypeName = row["ETypeName"].ToString();
                model.ETypeDesc = row["ETypeDesc"] != null ? row["ETypeDesc"].ToString() : "";
            }
            return _dal.AddEType(model);
        }

        /// <summary>
        /// 修改异常类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool ModifyEType(string data)
        {
            var model = new ETypeEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.ETypeCode = row["ETypeCode"].ToString();
                model.ETypeName = row["ETypeName"].ToString();
                model.ETypeDesc = row["ETypeDesc"] != null ? row["ETypeDesc"].ToString() : "";
            }
            return _dal.ModifyEType(model);
        }

        /// <summary>
        /// 获取异常类别单条信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string GetETypeInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetETypeInfo(id));
        }

        /// <summary>
        /// 删除异常类别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Remove(string id)
        {
            return _dal.Remove(id);
        }

        /// <summary>
        /// 获取异常类别分页
        /// </summary>
        /// <returns></returns>
        public string GetETypeList(ETypeQcEntity qcmodel)
        {
            var total = _dal.GetETypeCount(qcmodel);
            var list = _dal.GetETypeList(qcmodel);
            return JsonHelper.Encode(total, list);
        }
    }
}
